package com.guet.ltomanagement.controller;

import com.guet.ltomanagement.common.entities.ResultBody;
import com.guet.ltomanagement.service.SysUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author sjj
 * @Description //TODO 测试controller
 * @Date 2021/10/17 2021/10/17
 */
@Api(tags = "测试用接口")
@RestController
public class TestController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public ResultBody test() {
        return ResultBody.success(sysUserService.list());
    }
    @PreAuthorize("hasAuthority('sys:user:list')")
    @GetMapping("/test/pass")
    public ResultBody pass() {

        // 加密后密码
        String password = bCryptPasswordEncoder.encode("111111");

        boolean matches = bCryptPasswordEncoder.matches("111111", password);

        System.out.println("匹配结果：" + matches);

        return ResultBody.success(password);
    }
}
